package nl.hr.minor.mobilelife.j1213.jlr.flow;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

/**
 * Adapter used to display all levels in the menu.
 * @author Leon
 *
 */
public class ButtonAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<Button> buttonList;

	// Gets the context so it can be used later  
	public ButtonAdapter(Context c, ArrayList<Button> buttonList) {
		this.context = c;
		this.buttonList = buttonList;
	}  

	// Total number of things contained within the adapter  
	public int getCount() {  
		return buttonList.size();  
	}  

	// Require for structure, not really used in my code.  
	public Object getItem(int position) {  
		return null;  
	}  

	// Require for structure, not really used in my code. Can  
	// be used to get the id of an item in the adapter for  
	// manual control.  
	public long getItemId(int position) {  
		return position;  
	}  

	public View getView(int position, View convertView, ViewGroup parent) {
		Button b = buttonList.get(position);
		b.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Intent intent = new Intent(context, FlowLevelActivity.class);
				intent.putExtra("levelCode", (Integer)v.getTag());
				context.startActivity(intent);		
			}
		});
		return b;
	}  
}  